package com.msa.msaportal.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.msa.msaportal.common.hibernate.HibernateBaseDao;
import com.msa.msaportal.common.hibernate.HibernateSimpleDao;
import com.msa.msaportal.dao.ITemplateDao;
import com.msa.msaportal.entity.PortalExample;
import com.msa.msaportal.entity.PortalheaderEntity;
import com.msa.msaportal.entity.Template;

public class TemplateDaoImpl extends HibernateBaseDao<Template, Integer> implements ITemplateDao {
	

	@Override
	public void addTemplate(Template template) {
		// TODO Auto-generated method stub
		this.sessionFactory.getCurrentSession().save(template);
	}
	

	@Override
	public void delTemplate(String tresourse_Id) {
		// TODO Auto-generated method stub
		//Template template = (Template) this.sessionFactory.getCurrentSession().get(Template.class,id);
		//int id = Integer.parseInt(tresourse_Id);
		String hql="from Template t where t.tsource_id=?";
		Template findUnique = (Template) this.findUnique(hql, tresourse_Id);
		
		this.sessionFactory.getCurrentSession().delete(findUnique);
		
		
		
	}
	

	@Override
	public Template getObjById(Integer tid) {
		System.out.println("template:"+tid);
		Template template = (Template) this.getSession().get(Template.class, tid);
		return template;
	}
	

	@Override
	protected Class<Template> getEntityClass() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void savePortal(PortalExample portal) {
		this.sessionFactory.getCurrentSession().save(portal);
		
	}


	@Override
	public Template findByTsourse_Id(String tresourse_Id) {
		// TODO Auto-generated method stub
		String hql="from Template t where t.tsource_id=?";
		Template findUnique = (Template) this.findUnique(hql, tresourse_Id);
		
		return findUnique;
	}


//	@Override
//	public void saveHeaderToTemplate(PortalheaderEntity header) {
//		// TODO Auto-generated method stub
//		this.sessionFactory.getCurrentSession().save(header);
//	}


	@Override
	public void addHeadOrFoontToTmp(Template template) {
		this.getSession().update(template);
	}


	@Override
	public void updateTemplate(Template template) {
		
		this.getSession().update(template);
	}
	

}
